package com.ruoyi.repairGroup.service.impl;

import com.ruoyi.project.domain.HouseProjectT;
import com.ruoyi.project.domain.HouseRepairCheckT;
import com.ruoyi.repairArea.domain.HouseRepairAreaT;
import com.ruoyi.repairArea.mapper.HouseRepairAreaTMapper;
import com.ruoyi.repairGroup.domain.HouseRepairGroupT;
import com.ruoyi.repairGroup.mapper.HouseRepairGroupTMapper;
import com.ruoyi.repairGroup.service.IHouseRepairGroupTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 楼宇维修明细表Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@Service
public class HouseRepairGroupTServiceImpl implements IHouseRepairGroupTService 
{
    @Autowired
    private HouseRepairGroupTMapper houseRepairGroupTMapper;
    @Autowired

    private HouseRepairAreaTMapper houseRepairAreaTMapper;

    /**
     * 查询楼宇维修明细表
     * 
     * @param repairId 楼宇维修明细表主键
     * @return 楼宇维修明细表
     */
    @Override
    public HouseRepairGroupT selectHouseRepairGroupTByRepairId(Long repairId)
    {
        return houseRepairGroupTMapper.selectHouseRepairGroupTByRepairId(repairId);
    }

    /**
     * 查询楼宇维修明细表列表
     * 
     * @param houseRepairGroupT 楼宇维修明细表
     * @return 楼宇维修明细表
     */
    @Override
    public List<HouseRepairGroupT> selectHouseRepairGroupTList(HouseRepairGroupT houseRepairGroupT)
    {
        return houseRepairGroupTMapper.selectHouseRepairGroupTList(houseRepairGroupT);
    }

    @Override
    public HouseRepairGroupT selectHouseRepairGroupSum(HouseRepairGroupT houseRepairGroupT)
    {
        return houseRepairGroupTMapper.selectHouseRepairGroupSum(houseRepairGroupT);
    }

    /**
     * 新增楼宇维修明细表
     * 
     * @param houseRepairGroupT 楼宇维修明细表
     * @return 结果
     */
    @Override
    public int insertHouseRepairGroupT(HouseRepairGroupT houseRepairGroupT)
    {
        return houseRepairGroupTMapper.insertHouseRepairGroupT(houseRepairGroupT);
    }

    /**
     * 修改楼宇维修明细表
     * 
     * @param houseRepairGroupVO 楼宇维修明细表
     * @return 结果
     */
    @Override
    @Transactional
    public int updateHouseRepairGroupT(HouseRepairGroupT houseRepairGroupVO, HouseRepairCheckT houseRepairCheckO, HouseProjectT houseProjectT)
    {
        houseRepairGroupTMapper.insertRepairCheck(houseRepairCheckO);
        houseRepairGroupTMapper.updateRepairMoneyForCheck(houseRepairGroupVO);
        HouseRepairAreaT repairVO=houseRepairAreaTMapper.sumNoMoney(houseProjectT);
        houseProjectT.setPayMoney(repairVO.getPayMoney());
        return houseRepairGroupTMapper.updateProjectMoneyForCheck(houseProjectT);
    }
    @Transactional
    public int updateProjectAndRepair(HouseProjectT projectVO, List<HouseRepairGroupT> repairListTemp)
    {
        for(HouseRepairGroupT vo:repairListTemp){
            houseRepairGroupTMapper.updateRepair(vo);
        }
        HouseRepairAreaT projectTemp = new HouseRepairAreaT();
        projectTemp=houseRepairAreaTMapper.sumNoMoney(projectVO);
        projectVO.setNoMoney(projectTemp.getNoMoney());
        return houseRepairGroupTMapper.updateProjectForTrueMoney(projectVO);
    }
    public HouseRepairGroupT getRepairDetail(HouseRepairGroupT houseRepairGroupT)
    {
        return houseRepairGroupTMapper.getRepairDetail(houseRepairGroupT);
    }
}
